home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / flxlist.zip / FLEXLIST.INT < prev    next >
Text File  |  1990-03-05  |  4KB  |  132 lines

  1. {
  2.  
  3.     flexlist.pas
  4.     3-5-90
  5.     Generic hybrid stack-queue-list-array object.
  6.  
  7.     Copyright 1990
  8.     John W. Small
  9.     All rights reserved
  10.  
  11.     PSW / Power SoftWare
  12.     P.O. Box 10072
  13.     McLean, Virginia 22102 8072
  14.  
  15.     This software is offered a shareware, meaning try before
  16.     you buy.  If you find it useful and are using it in your
  17.     applications a registration fee of $14 is required! Upon
  18.     registration you will be sent source code along with the
  19.     latest example programs on a DOS formatted 5 1/4" disk.
  20.  
  21.     Run flexlist.dem, the demo program, while studying this
  22.     source code to gain the most rapid understanding of
  23.     FlexList!
  24.  
  25.     Anytime your Turbo Pascal 5.5 application requires a
  26.     stack, queue, or linked list, simply include "flexlist"
  27.     in its "uses" clause.  Next declare your stack, queue,
  28.     or list as a variable of type "Flist".  Flist, a
  29.     flexlist object, is really a generic hybrid
  30.     stack-queue-list-array data structure.  Your Flist
  31.     variable can be initialized to store any type of data.
  32.     The Flist object has 31 methods for accessing your
  33.     "list" as a stack, queue, list, or array
  34.     interchangeably!  You can push, pop, insert, delete,
  35.     sort, store, recall, or find to name but just a few
  36.     operations.  The complement of Flist methods allows you
  37.     to access your list's data by value (copy) or by
  38.     reference (pointer) as well as to move nodes directly
  39.     between lists.  And your application's code size won't
  40.     continue to grow when you add new types of lists either,
  41.     since the Flist object is generic, able to hold any type
  42.     of data, record or object.  Since FlexLists are
  43.     initialized at run time, the data they hold or even
  44.     their creation can be specified at run time thus
  45.     allowing your application new dimensions of adaptibility
  46.     to user specifications.  And with FlexList you can
  47.     quickly construct lists of lists or other composite
  48.     structures.  FlexList will save you time, money, code
  49.     space and headaches!
  50.  
  51.  
  52.     For example:
  53.  
  54.         type myStackItem = integer;
  55.  
  56.         var myStack : Flist;
  57.  
  58.         begin
  59.             writeln('Count backwards from ten by pushing 1 to 10');
  60.             writeln('onto the stack and then popping and displaying');
  61.             writeln('the results.');
  62.             myStack.init(sizeof(myStackItem));
  63.             for i := 1 to 10 do
  64.                 myStack.push(i);
  65.             myStack.pop(i);
  66.             while myStack.ok do begin
  67.                 writeln(i);
  68.                 myStack.pop(i)
  69.                 end
  70.             write('Press ''Enter'' to quit.');
  71.             readln
  72.         end.
  73.  
  74.  
  75. }
  76.  
  77. unit flexlist;
  78.  
  79. interface
  80.  
  81.     type
  82.  
  83.         FlistData = word;
  84.  
  85.         FlistN = ^FlistNode;
  86.         FlistNode = record
  87.             next, prev : FlistN;
  88.             data : FlistData
  89.         end;
  90.  
  91.         FlistTest = function (var buf1, buf2) : integer;
  92.  
  93.         FlistH = ^Flist;
  94.         Flist = object
  95.             front, current, rear : FlistN;
  96.             curNum, nodes, dataSize : word;
  97.             ok : boolean;
  98.             constructor init(dataLen : word);
  99.             constructor unpack(cellLen, cells : word; var arrayBuf);
  100.             procedure   clr;
  101.             procedure   push(var buf);
  102.             procedure   pushN(n : FlistN);
  103.             procedure   pop(var buf);
  104.             function    popN : FlistN;
  105.             procedure   top(var buf);
  106.             function    frontD : pointer;
  107.             procedure   insertQ(var buf);
  108.             procedure   insertQN(n : FlistN);
  109.             function    rearD : pointer;
  110.             procedure   mkcur(i : word);
  111.             function    currentD : pointer;
  112.             procedure   insert(var buf);
  113.             procedure   insertN(n : FlistN);
  114.             procedure   insertSort(var buf; test : FlistTest);
  115.             procedure   insertSortN(n : FlistN; test : FlistTest);
  116.             procedure   delete(var buf);
  117.             function    deleteN : FlistN;
  118.             function    next(var buf) : boolean;
  119.             function    nextD(var d : pointer) : boolean;
  120.             function    prev(var buf) : boolean;
  121.             function    prevD(var d : pointer) : boolean;
  122.             procedure   get(var buf);
  123.             procedure   put(var buf);
  124.             procedure   store(var buf; location : word);
  125.             procedure   recall(var buf; location : word);
  126.             function    find(var buf; test : FlistTest) : boolean;
  127.             procedure   sort(test : FlistTest);
  128.             function    pack : pointer;
  129.             function    packPtrs : pointer;
  130.             destructor  done; virtual;
  131.         end;
  132.